<?php
/**
 * Created by PhpStorm.
 * User: DELL-PC
 * Date: 2018/8/2
 * Time: 9:46
 */

namespace J\Schema;


/**
 * 规则定义
 */
class Syntax
{
    const KEY_ALL      = '*';
    const KEY_ID       = 'id';
    const KEY_STATUS   = 'status';
    const KEY_KEY      = 'key';
    const KEY_RELATION = 'relation';
    const KEY_TYPE     = 'type';
    const KEY_BASE     = 'base';
    const KEY_DRIVER   = 'driver';
    const KEY_TREE     = 'tree';
    const KEY_QUERY    = 'query';
    const KEY_WHERE    = 'where';

    const OPERATOR_IN         =  'IN';
    const OPERATOR_NOT_IN     =  'NOTIN';
    const OPERATOR_IS_NULL    =  'ISNULL';
    const OPERATOR_SET_NULL   =  'SETNULL';
    const OPERATOR_NOT_NULL   =  'NOTNULL';
    const OPERATOR_NOW        =  'NOW';
    const OPERATOR_RAND       =  'RAND';
    const OPERATOR_BETWEEN    =  'BETWEEN';
    const OPERATOR_REPLACE    =  'REPLACE';
    const OPERATOR_LIKE       =  'LIKE';
    const OPERATOR_NOT_LIKE   =  'NOTLIKE';
    const OPERATOR_EXPRESSION =  'expression';
    const OPERATOR_LINK       =  'LINK';

    const KEY_ELEMENTS        =  'elements';
    const KEY_COLLECTIONS     =  'collections';
    const KEY_CONTROLLERS = 'controllers';
    const KEY_OPTIONS = 'options';
    const KEY_EXTENDS = 'extends';
    const KEY_INSTALL = 'install';
    const KEY_RESOURCE = 'resource';

    const FETCH_ADD           =  -1;

    const KEY_VIEW            = 'view';
    const DISPLAY_TREE        = 'TreeView';
    const DISPLAY_TABLE       = 'TableView';
    const DISPLAY_FORM        = 'FormView';
    const DISPLAY_SELECT      = 'SelectView';
    const DISPLAY_CHART       = 'ChartView';
    const DISPLAY_MODULE = 'Module';

    const ACTION_ADD          = 1;
    const ACTION_EDIT         = 2;
    const ACTION_COMPARE      = 0;
    const ACTION_CALCULATE    = 3;

    // 属性 0x00ff0000
    const MASK_ATTRIBUTE  = 0xff000000;
    // 验证 0x0000f000
    const MASK_VALID      = 0x00f00000;
    // 类型 0x00000fff
    const MASK_MAIN_TYPE  = 0x000000ff;
    const MASK_SUBTYPE    = 0x0000f000;
    const MASK_LENGTH     = 0x00000f00;
    const MASK_VALUE      = self::MASK_MAIN_TYPE | self::MASK_SUBTYPE | self::MASK_LENGTH;

    // 多选字段
    const MASK_MULTI      = 0x80000000;
    // 索引字段
    const MASK_INDEX      = 0x40000000;
    // 唯一性字段
    const MASK_UNIQUE     = 0x20000000;
    // 自增字段
    const MASK_AUTO_INC   = 0x10000000;
    // 虚拟列
    const MASK_VIRTUAL    = 0x06000000;
    const MASK_N_N        = 0x04000000;
    const MASK_1_N        = 0x02000000;
    // 外键
    const MASK_F_KEY      = 0x01000000;
    // 非空
    const MASK_NOT_NULL   = 0x00100000;
    // 必填
    const MASK_MUST       = 0x00200000;
    // 类型详解
    const VALUE_INTEGER   = 0x00000001;
    const VALUE_FLOAT     = 0x00000002;
    const VALUE_DATE_TIME = 0x00000004;
    const VALUE_STRING    = 0x00000008;
    const VALUE_OBJ       = 0x00000010;
    const VALUE_SET       = 0x00000020;
    const SPECIAL_TYPE    = 0x00000080;


    // 隶属列
    const LINK_BLS        = self::MASK_F_KEY;
    // 包含列
    const LINK_HAS        = self::MASK_1_N | self::MASK_F_KEY;
    // 连接列
    const LINK_MANY       = self::MASK_N_N | self::MASK_F_KEY;


    const VALUE_BIT        = 0x00000001;
    const VALUE_TINY       = 0x00000101;
    const VALUE_SMALLINT   = 0x00000201;
    const VALUE_MEDIUMINT  = 0x00000301;
    const VALUE_INT        = 0x00000401;
    const VALUE_BIGINT     = 0x00000501;
    const VALUE_UNSIGNED   = 0x00001000;
    // 为ID单独设计标志位，防止其他整形域被错误处理
    const VALUE_ID         = 0x00002000 | self::VALUE_UNSIGNED | self::VALUE_INT;
    const VALUE_SELECT     = 0x00004000;

    const VALUE_BOOL      = self::VALUE_BIT | 0x00004000;
    const VALUE_DOUBLE    = 0x00001000 | self::VALUE_FLOAT;
    const VALUE_TEXT      = self::VALUE_STRING | 0x00008000;
    const VALUE_IP        = self::VALUE_STRING | 0x00004000;
    const MASK_NUM        = self::VALUE_FLOAT | self::VALUE_INTEGER; // 检测用


    const FIELD_INNER     = 0;

    const FIELD_BLS       =  self::VALUE_INT | self::LINK_BLS;
    const FIELD_ID        =  self::MASK_NOT_NULL | self::MASK_MUST |
                             self::MASK_INDEX | self::MASK_UNIQUE  |
                             self::MASK_AUTO_INC | self::VALUE_ID;
    const FIELD_MULTISET  =  self::VALUE_INT | self::MASK_MULTI;

    const FIELD_DATE      = self::VALUE_DATE_TIME | 0x00001000;
    const FIELD_DATE_TIME = self::VALUE_DATE_TIME | 0x00003000;
    const FIELD_TIME      = self::VALUE_DATE_TIME | 0x00002000;


}